package com.ccb.lms.dao;

import java.sql.SQLException;
import java.util.List;

import com.ccb.lms.model.Authority;
import com.ccb.lms.util.BasePage;
import com.ibatis.sqlmap.client.SqlMapClient;

public class AuthorityDAO implements IAuthorityDAO {
	private SqlMapClient sqlMapClient = null;

	public SqlMapClient getSqlMapClient() {
		return sqlMapClient;
	}

	public void setSqlMapClient(SqlMapClient sqlMapClient) {
		this.sqlMapClient = sqlMapClient;
	}
	public boolean insertAuthority(Authority authority) throws SQLException {
		// TODO Auto-generated method stub
		sqlMapClient.insert("authority.insertAuthority", authority);
		return true;
	}

	public boolean deleteAuthority(Integer authorityNO) throws SQLException {
		// TODO Auto-generated method stub
		sqlMapClient.delete("authority.deleteAuthority", authorityNO);
		return true;
	}

	public boolean updateAuthority(Authority authority) throws SQLException {
		// TODO Auto-generated method stub
		sqlMapClient.update("authority.updateAuthority", authority);
		return true;
	}

	

	public Authority getAuthorityByNO(Integer authorityNO) throws SQLException {
		// TODO Auto-generated method stub		
		return (Authority) sqlMapClient.queryForObject("authority.getAuthorityByNO", authorityNO);
	}

	public int getAuthorityCount() throws SQLException {
		// TODO Auto-generated method stub
		return (Integer) sqlMapClient.queryForObject("authority.recordCount");
	}

	public BasePage getBasePage(int currentPage, int showRecordNum)
			throws SQLException {
		// TODO Auto-generated method stub
		return new BasePage(currentPage, getAuthorityCount(), showRecordNum);
	}

	@SuppressWarnings("unchecked")
	public List<Authority> getAuthorityByPage(BasePage basePage) throws SQLException {
		// TODO Auto-generated method stub
		return sqlMapClient.queryForList("authority.getAuthorityByPage", basePage);
	}

	public List<Authority> getAllAuthorities() throws SQLException {
		// TODO Auto-generated method stub
		return sqlMapClient.queryForList("authority.getAllAuthorities");
	}
	
}
